package app.sceledroid.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import app.sceledroid.R;
import app.sceledroid.entity.forum.Discussion;

public class DiscussionAdapter extends ArrayAdapter<Discussion> {

	private ArrayList<Discussion> Discussions;
	
	public DiscussionAdapter(Context context, int textViewResourceId,
			ArrayList<Discussion> Discussions) {
		super(context, textViewResourceId, Discussions);
		// TODO Auto-generated constructor stub
		this.Discussions = Discussions;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		if (v == null) {
			Context context = super.getContext();
			LayoutInflater vi = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.forum_discussion_item, null);
		}
		Discussion d = Discussions.get(position);
		
		TextView discussionName = (TextView)v.findViewById(R.id.discussionItemName);
		discussionName.setText(d.getTopic());
		TextView discussionCreator = (TextView)v.findViewById(R.id.discussionCreator);
		discussionCreator.setText(d.getCreator().getUsername());
		TextView discussionLastResponse = (TextView)v.findViewById(R.id.userLastResponse);
		discussionLastResponse.setText(d.getLastResponse());
		
		return v;
	}
}
